<?php
class mysql
{
	var $hostname = "";		//ݿ
	var $username = "";		//ݿ½û
	var $password = "";		//½
	var $database = "";		//ݿ
	var $linkid = "";		//ݿID
	var $result = "";		//صĲѯϢ
	var $array="";			//Ϣ
	var $number=0;	

	function mysql($hostname,$username,$password,$database)   
	{    
		$this->linkid = mysql_pconnect($hostname,$username,$password);
		$test = mysql_select_db($database,$this->linkid);
		if(!$test)
		{
			$this->error("Cound no connect to the database.");	
		}
	}


	function query($query)                                  
	{
		$this->result = mysql_query($query);
		if(!$this->result)
		{
			$this->error("MySql Error!");
		}
	}
	
	function num($query)
	{
		$this->query($query);
		$this->number = mysql_num_rows($this->result);
	}
	
	function getnum($query)
	{
	   $this->num($query);
	   return $this->number;
	}

	function fetch($query)
	{
		$this->num($query);
		for ($i=0 ;$i<$this->number;$i++)
        {
			$array[$i]=mysql_fetch_array($this->result) ;
		}
		return $array;
	}
	function insert_id($query) 
	{
		$this->result = mysql_query($query);
		if(!$this->result)
		{
			$this->error("MySql Error!");
		}
		else
		{
			$id = mysql_insert_id();
			return $id;
		}		
	}
	function error($str,$url="")							
	{
		if($url!="")
		{
			echo"<meta http-equiv=\"refresh\" content=\"0;URL=$url\">";
			exit();
		}
		else
		{
			echo "<hr>" . $str;
	   		exit;	
		}
	}
}

?>